//
//  FQDColumnHeaderSubscribeCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/23/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDColumnHeaderSubscribeCell.h"
#import "FQDColumnCrossLineLabel.h"
#import "FQDColumnUsersView.h"
#import "FQDRestModel.h"

#import "Masonry.h"

@interface FQDColumnHeaderSubscribeCell ()

@property (nonatomic, strong) FQDColumnCrossLineLabel *lineLabel;
@property (nonatomic, strong) FQDColumnUsersView *usersView;

@end

@implementation FQDColumnHeaderSubscribeCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareCell];
    }
    return self;
}

- (void)prepareCell
{
    self.backgroundColor = [UIColor whiteColor];
    _lineLabel = [[FQDColumnCrossLineLabel alloc] init];
    [self.contentView addSubview:_lineLabel];
    
    WeakSelf;
    [_lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView);
        make.left.equalTo(weakSelf.contentView).offset(10);
        make.right.equalTo(weakSelf.contentView).offset(-10);
        make.height.equalTo(@41);
    }];
    
    _usersView = [[FQDColumnUsersView alloc] init];
    [self.contentView addSubview:_usersView];
    
    [_usersView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.lineLabel.mas_bottom);
        make.left.equalTo(weakSelf.contentView).offset(25);
        make.right.equalTo(weakSelf.contentView).offset(-25);
        make.bottom.equalTo(weakSelf.contentView).offset(-4);
    }];
}

- (void)setSubscribers:(NSArray *)subscribers
{
    _subscribers = subscribers;
    
    NSString *subscribeString = [NSString stringWithFormat:@"%@人订阅了本栏目", @([subscribers count])];
    self.lineLabel.labelText = ([subscribers count] > 0) ? subscribeString : @"";
    self.usersView.users = subscribers;
//    if ([subscribers count] > 1) {
//        FQDAuthor *author = [subscribers firstObject];
//        self.usersView.selectedUserId = author.ID;
//    } else {
//        self.usersView.selectedUserId = nil;
//    }
}

+ (NSString *)reuseId
{
    return @"FQDColumnHeaderSubscribeCell";
}

@end
